/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "access")
@NamedQueries({
    @NamedQuery(name = "Access.findAll", query = "SELECT a FROM Access a"),
    @NamedQuery(name = "Access.findByPharmacyId", query = "SELECT a FROM Access a WHERE a.accessPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Access.findByUserId", query = "SELECT a FROM Access a WHERE a.accessPK.userId = :userId"),
    @NamedQuery(name = "Access.findByUserIdByPharmacyId", query = "SELECT a FROM Access a WHERE a.accessPK.userId = :userId AND a.accessPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Access.findByMenuId", query = "SELECT a FROM Access a WHERE a.accessPK.menuId = :menuId"),
    @NamedQuery(name = "Access.findBySubmenuId", query = "SELECT a FROM Access a WHERE a.accessPK.submenuId = :submenuId"),
    @NamedQuery(name = "Access.findByOptionId", query = "SELECT a FROM Access a WHERE a.accessPK.optionId = :optionId"),
    @NamedQuery(name = "Access.findByUserIdByPharmacyIdByMenuIdBySubmenuId", query = "SELECT a FROM Access a WHERE a.accessPK.userId = :userId AND a.accessPK.pharmacyId = :pharmacyId AND a.accessPK.menuId = :menuId AND a.accessPK.submenuId = :submenuId"),
    @NamedQuery(name = "Access.findByPharmacyIdByUserIdByMenuIdBySubmenuIdByOptionId", query = "SELECT a FROM Access a WHERE a.accessPK.pharmacyId = :pharmacyId AND a.accessPK.userId = :userId AND a.accessPK.menuId = :menuId AND a.accessPK.submenuId = :submenuId AND a.accessPK.optionId = :optionId")})
public class Access implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId													
    protected AccessPK accessPK;
    @JoinColumns({
        @JoinColumn(name = "menuId", referencedColumnName = "menuId", insertable = false, updatable = false),
        @JoinColumn(name = "submenuId", referencedColumnName = "submenuId", insertable = false, updatable = false),
        @JoinColumn(name = "optionId", referencedColumnName = "optionId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Option option;
    @JoinColumns({
        @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId", insertable = false, updatable = false),
        @JoinColumn(name = "userId", referencedColumnName = "userId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Userpharmacy userpharmacy;

    public Access() {
    }

    public Access(AccessPK accessPK) {
        this.accessPK = accessPK;
    }

    public Access(int pharmacyId, int userId, short menuId, short submenuId, short optionId) {
        this.accessPK = new AccessPK(pharmacyId, userId, menuId, submenuId, optionId);
    }

    public Access(Option option,Userpharmacy userPharmacy) {
        this.accessPK = new AccessPK(userPharmacy.getUserpharmacyPK().getPharmacyId(),userPharmacy.getUserpharmacyPK().getUserId(),option.getOptionPK().getMenuId(),option.getOptionPK().getSubmenuId(),option.getOptionPK().getOptionId());
    }
    
    public AccessPK getAccessPK() {
        return accessPK;
    }

    public void setAccessPK(AccessPK accessPK) {
        this.accessPK = accessPK;
    }
    
    public Option getOption() {
        return option;
    }

    public void setOption(Option option) {
        this.option = option;
    }

    public Userpharmacy getUserpharmacy() {
        return userpharmacy;
    }

    public void setUserpharmacy(Userpharmacy userpharmacy) {
        this.userpharmacy = userpharmacy;
    }
/*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accessPK != null ? accessPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Access)) {
            return false;
        }
        Access other = (Access) object;
        if ((this.accessPK == null && other.accessPK != null) || (this.accessPK != null && !this.accessPK.equals(other.accessPK))) {
            return false;
        }
        return true;
    }

    @Override */
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Access[ accessPK=" + accessPK + " ]";
    }
    
}
